#!/bin/sh
#开始前获取全局配置参数
#每五秒获取一次cpu load,MySQL全局信息，InnoDB引擎相关信息，线程信息 
INTERVAL=5
PREFIX=$INTERVAL-sec-status
RUNFILE=/mysql/app/sysbench/run
mysql -uroot -proot -e 'show global variables'>>mysql-variables
while  test -e $RUNFILE; do
        file=$(date +%F_%H)
        sleep=$(date +%s.%N |awk "{print $INTERVAL -(\$1 % $INTERVAL)}")
        sleep $sleep
        ts="$(date +"TS %s.%N %F %T")"
        loadavg="$(uptime)"                                 #通过uptime命令获取cpu load
        echo "$ts $loadavg">> $PREFIX-${file}-status
        mysql -uroot -proot  -e "show global status" >> $PREFIX-${file}-status &   #获取MySQL全局信息
        echo "$ts $loadavg">> $PREFIX-${file}-innodbstatus
        mysql -uroot -proot  -e "show engine innodb status\G" >> $PREFIX-${file}-innodbstatus &    #获取引擎信息
        echo "$ts $loadavg">> $PREFIX-${file}-processlist
        mysql -uroot -proot  -e "show full processlist\G" >>$PREFIX-${file}-processlist &  #获取线程信息
        echo $ts
done
echo Exiting because $RUNFILE not exist  

